package logic

import (
	"context"
	"fmt"
	"rpc/model/redis"

	"rpc/goods"
	"rpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsStockLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsStockLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsStockLogic {
	return &GoodsStockLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodsStockLogic) GoodsStock(in *goods.GoodsStockRequest) (*goods.GoodsStockResponse, error) {
	// todo: 查询商品库存

	res := redis.GetGoodsStock(int(in.GoodsId))

	//获取的库存
	fmt.Println("获取的库存", res)

	return &goods.GoodsStockResponse{GoodsStock: int64(res)}, nil
}
